//
//  APIConfig.swift
//  aishop
//
//  Created by tuguowei on 2025/10/15.
//

import Foundation

struct APIConfig {
    // 请求域名 - 对应uniapp的HTTP_REQUEST_URL
    static let baseURL = "https://sgapi.ttxcx.net/api/front"
    
    // 请求头配置
    static let headers = [
        "Content-Type": "application/json"
    ]
    
    // Token名称
    static let tokenName = "Authori-zation"
    
    // 分页限制
    static let pageLimit = 10
    
    // 缓存时间
    static let cacheExpire = 0
}

// API端点枚举
enum APIEndpoint {
    case indexInfo
    case bottomNavigation
    case categoryFirst
    case categoryThird(Int)
    case coupons
    case userCoupons
    case userCouponsList(type: String) // type: usable/unusable
    case couponCollectionCenter
    case couponReceive(Int)
    case productCouponList(Int) // productId
    case articleList(cid: Int)
    case diyData(Int)
    case openAdv
    case productList
    case productDetail
    case productByIds(String) // 商品ID列表，逗号分隔
    case userInfo
    case recommendProducts
    
    // 商户入驻相关端点
    case agreementInfo
    case merchantCategoryList
    case merchantTypeList
    case merchantSendSettledCode
    case uploadImage
    case merchantSettledApply
    
    // 用户服务相关端点
    case userIntegral
    case userIntegralList
    case userIntegralInfo
    case userMoney
    case userMoneyInfo
    case userSign
    case userSignInfo
    case signRecordList
    case userCollection
    case merchantCollectionCancel(Int)
    case userAddress
    case userAddressAdd
    case userAddressEdit(Int)
    case userAddressDelete(Int)
    case userAddressDefault(Int)
    case cityList(parentId: Int, regionType: Int)
    case userSpread
    case userSettled
    case userGrade
    case userGradeExp
    case followAuthor(authorId: String)
    case likeNote(noteId: String)
    case topicCount
    case userHome
    case noteAuthorList
    case replyList
    case topicList
    case topicRecommendList
    case noteDetail
    case userCenterMenu
    case getUserInfo
    case articleBannerList
    case discoverList
    case communityCategoryList
    case recommendAuthorList
    case followList
    // 登录相关端点 - 统一定义
    case login(path: String)  // 如 mobile/password, mobile/captcha
    case register
    case sendSmsCode
    // 购物车相关端点
    case cartList
    case cartAdd
    case cartCount
    case cartNum
    case cartDelete
    case cartResetCart
    case cartCalculatePrice
    case cartToCollect
    case cartBatchAdd
    case UserProfile
    case UserProfileEdit
    case cartCount1
    // 配置相关端点
    case themeConfig
    
    // 订单相关端点
    case orderList
    case orderDetail(String)  // orderNo
    
    // 商品详情相关端点
    case productReplyDetail(Int)  // productId
    case productReplyConfig(Int)  // productId
    case shoppingUserIntegral  // 购物时获取用户积分
    
    var path: String {
        switch self {
        case .indexInfo:
            return "/index/info"
        case .bottomNavigation:
            return "/index/get/bottom/navigation"
        case .categoryFirst:
            return "/product/category/get/first"
        case .categoryThird(let id):
            return "/product/category/get/third/\(id)"
        case .coupons:
            return "/coupon/page/list"
        case .userCoupons:
            return "/coupon/user/list"
        case .userCouponsList(_):
            return "/coupon/user/list"
        case .couponCollectionCenter:
            return "/coupon/voucher/collection/center"
        case .couponReceive(let id):
            return "/coupon/receive/\(id)"
        case .productCouponList:
            return "/coupon/page/list"
        case .articleList(let cid):
            return "/article/list/\(cid)"
        case .diyData(let id):
            return "/pagediy/info/\(id)"
        case .openAdv:
            return "/index/splash/ad/info"
        case .productList:
            return "/product/list"
        case .productDetail:
            return "/product/detail"
        case .productByIds(let ids):
            return "/product/byids/\(ids)"
        case .userInfo:
            return "/user/info"
        case .recommendProducts:
            return "/index/product/list"
        case .userCenterMenu:
            return "/user/center/info/menu"
        case .getUserInfo:
            return "/user/center/info"
        case .login(let path):
            return "/login/\(path)"
        case .register:
            return "/register"
        case .sendSmsCode:
            return "/login/send/code"
        case .articleBannerList:
            return "/article/banner/list"
        case .discoverList:
            return "/community/note/list"
        case .communityCategoryList:
            return "/community/category/list"
        case .recommendAuthorList:
            return "/community/recommend/author/list"
        case .followList:
            return "/community/follow/list"
        case .followAuthor(let authorId):
            return "/community/follow/author/\(authorId)"
        case .likeNote(let noteId):
            return "/community/note/like/\(noteId)"
        case .topicCount:
            return "/community/topic/count"
        case .userHome:
            return "/community/user/home"
        case .noteAuthorList:
            return "/community/note/author/list"
        case .replyList:
            return "/community/reply/list"
        case .topicList:
            return "/community/topic/list"
        case .topicRecommendList:
            return "/community/topic/recommend/list"
        case .noteDetail:
            return "/community/note/detail"
        case .UserProfile:
            return "/user/info"
        case .UserProfileEdit:
            return "/user/user/edit"    
        // 购物车相关路径
        case .cartList:
            return "/cart/list"
        case .cartAdd:
            return "/cart/add"
        case .cartCount:
            return "/cart/count"
        case .cartNum:
            return "/cart/num"
        case .cartDelete:
            return "/cart/delete"
        case .cartResetCart:
            return "/cart/resetcart"
        case .cartCalculatePrice:
            return "/cart/calculate/price"
        case .cartToCollect:
            return "/cart/to/collect"
        case .cartBatchAdd:
            return "/cart/batch/add"
            
        // 配置相关路径
        case .themeConfig:
            return "/index/color/config"
        // 用户服务相关路径
        case .userIntegral:
            return "/user/center/integral/list"
        case .userIntegralList:
            return "/user/center/integral/list"
        case .userIntegralInfo:
            return "/user/center/my/integral"
        case .userMoney:
            return "/user/balance/list"
        case .userMoneyInfo:
            return "/user/center/my/account"
        case .userSign:
            return "/user/sign/list"
        case .userSignInfo:
            return "/sign/page/info"
        case .signRecordList:
            return "/sign/record/list"
        case .userCollection:
            return "/collect/merchant/list"
        case .merchantCollectionCancel(let id):
            return "/collect/cancel/merchant/\(id)"
        case .userAddress:
            return "/address/list"
        case .userAddressAdd:
            return "/address/add"
        case .userAddressEdit(_):
            return "/address/edit"
        case .userAddressDelete(let id):
            return "/address/delete/\(id)"
        case .userAddressDefault(let id):
            return "/address/set/default/\(id)"
        case .cityList(let parentId, let regionType):
            return "/city/list?parentId=\(parentId)&regionType=\(regionType)"
        case .userSpread:
            return "/user/center/my/promotion"
        case .userSettled:
            return "/user/merchant/apply"
        case .userGrade:
            return "/user/grade/info"
        case .userGradeExp:
            return "/user/center/my/exp"
        // 商户入驻相关路径
        case .agreementInfo:
            return "/agreement/merincomminginfo"
        case .merchantCategoryList:
            return "/merchant/all/category/list"
        case .merchantTypeList:
            return "/merchant/all/type/list"
        case .merchantSendSettledCode:
            return "/merchant/send/settled/code"
        case .uploadImage:
            return "/upload/image"
        case .merchantSettledApply:
            return "/merchant/settled/apply"
        // 订单相关路径
        case .orderList:
            return "/order/list"
        case .orderDetail(let orderNo):
            return "/order/detail/\(orderNo)"
        case .productReplyDetail(let productId):
            return "/product/reply/detail/\(productId)"
        case .productReplyConfig(let productId):
            return "/product/reply/config/\(productId)"
        case .shoppingUserIntegral:
            return "/integral/shopping/get/user/integral"
        case .cartCount1:
            return "/cart/count"
        }
    }
    
    var fullURL: String {
        return APIConfig.baseURL + path
    }
}